package com.alibaba.middleware.hsf.dubbo;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ConsumerConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.middleware.hsf.guide.api.service.HelloWorldService;

/**
 * @author guanghao on 23/03/2018.
 */
public class DubboConsumer {
    public static void main(String[] args) {
        ApplicationConfig application = new ApplicationConfig();
        application.setName("dubbo-consumer");
//        application.setCompiler("jdk");
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setAddress("multicast://224.5.6.7:1234");
//        registryConfig.setAddress("zookeeper://127.0.0.1:2181");

        application.setRegistry(registryConfig);
        ConsumerConfig consumerConfig = new ConsumerConfig();
        consumerConfig.setFilter("customClientFilter");

        ReferenceConfig<HelloWorldService> referenceConfig = new ReferenceConfig<HelloWorldService>();
        referenceConfig.setApplication(application);
        referenceConfig.setInterface(HelloWorldService.class);

        referenceConfig.setConsumer(consumerConfig);
//        referenceConfig.setFilter("customClientFilter");
//        referenceConfig.setVersion("1.0.0");

        try {
            HelloWorldService helloWorldService = referenceConfig.get();
            System.out.println(helloWorldService.sayHi("arthur"));
//            ObjectHaveNotImplSerializable objectHaveNotImplSerializable = helloWorldService.getObjectHaveNotImplSerializable();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
